/**
 * Created by Lucky ye on 2016/10/19.
 */
//rem手机适配
new function (){
    var _self = this;
    _self.width = 640;//设置默认最大宽度
    _self.fontSize = 100;//默认字体大小
    _self.widthProportion = function(){var p = (document.body&&document.body.clientWidth||document.getElementsByTagName("html")[0].offsetWidth)/_self.width;return p>1?1:p<0.5?0.5:p;};
    _self.changePage = function(){
        document.getElementsByTagName("html")[0].setAttribute("style","font-size:"+_self.widthProportion()*_self.fontSize+"px !important");
    }
    _self.changePage();
    window.addEventListener('resize',function(){_self.changePage();},false);
};
function closeAndOpenPattern(){
    $("#close-pattern").click(function(){
        $(".work-pattern").fadeOut();
    })
    $("#show-pattern").click(function(){
        $(".work-pattern").fadeIn();
    })
};
//点击侧边栏显示
function show_menu(){
    $("#side_menu").css({"left":0+"%"});
    $("#side_menu").css({"transform":"translateX("+0+"px)","-webkit-transform":"transition("+0+"px)"});
    //console.log($(window).width());
    var windowWidth = $(window).width();
    var startX;
    var sideMenu = document.getElementById("side_menu");
    sideMenu.addEventListener('touchstart', function(e){
        /*lastXForMobile = e.changedTouches[0].pageX;
        pressedObj = this; // 记录被按下的对象*/

        // 记录开始按下时的点
        var touches = e.touches[0];
        startX = touches.pageX; // 横坐标
        //console.log("touchstart"+start.x+"+"+start.y);
        //$("#side_menu").css({"left":-100+"%"});
    });
    sideMenu.addEventListener('touchmove',function(e) {
        // 计算划动过程中x和y的变化量
        var touchesX = e.touches[0].pageX;
        //console.log("touchmove"+touches.pageX+"+"+touches.pageY);
        var touchmoveX = touchesX - startX;
        if(touchmoveX > 0){
            return;//大于零表示向右移动了
        }
        $("#side_menu").css({"transform":"translateX("+touchmoveX+"px)","transition":"left 0.5s","-webkit-transform":"transition("+touchmoveX+"px)","-webkit-transition":"left 0.5s"});
    })
    sideMenu.addEventListener('touchend', function(e){
        var touchesX = e.changedTouches[0].pageX - startX;
        if(touchesX > 0){
            return;
        }
        if(touchesX/windowWidth < -0.35){
            $("#side_menu").css({"left":-100+"%"});
        }else{
            $("#side_menu").css({"transform":"translateX("+0+"px)","transition":"left 1s","-webkit-transform":"transition("+0+"px)","-webkit-transition":"left 1s"});
        }
    });
}

